#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2018/1/17 0017 20:32
# @Author  : Arliki
# @File    : scrapy_1.py
import scrapy
from sct1.items import ScrItems


class Scr(scrapy.Spider):
    name = "scr1"
    # allowed_domains=["imooc.com"]
    start_urls = ["http://www.imooc.com/course/list"]
    print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")

    def parse(self, response):
        scr1_item = ScrItems()
        n = 0
        for box in response.xpath("//div[@class='course-card-container']"):
            print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
            scr1_item['url'] = "http://www.imooc.com" + box.xpath(".//@href").extract()[0]
            scr1_item['title'] = box.xpath('.//h3/text()').extract()[0].strip()
            scr1_item['img_url'] = box.xpath('.//@src').extract()[0]
            scr1_item['student'] = box.xpath('.//span/text()').extract()[1].strip()
            scr1_item['introduction'] = box.xpath('.//p/text()').extract()[0].strip()
            print(scr1_item)
            # with open('%s.json'%n,'a+',encoding='utf-8') as f:
            #     f.write(scr1_item['url'])


def run():
    pass


if __name__ == '__main__':
    run()
